function k(x){
    let sum = x;

    function inner(next){
        if(next === undefined){
            return sum;
        }
        sum += next;
        return inner;
    }
    return inner;
}

console.log(k(1)(2)(3)())
